package cn.com.ejiakanghu.web;

import cn.com.ejiakanghu.annotation.LoginUser;
import cn.com.ejiakanghu.core.vo.BaseResult;
import cn.com.ejiakanghu.service.UserManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * 个人中心
 */
@RestController
@RequestMapping("/user")
@Validated
public class UserController {
    private Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserManager userManager;

    /**
     * @api {post} /user/info 个人中心获取实时用户信息
     * @apiGroup 个人中心
     * @apiVersion 0.1.0
     * @apiDescription 个人中心获取实时用户信息
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/info")
    public BaseResult info(@LoginUser Integer userId) {
        return userManager.getUserInfo(userId);
    }

    /**
     * @api {post} /user/financeDetail 个人中心-代理用户-收支明细-获取收支明细数据
     * @apiGroup 个人中心
     * @apiParam {Integer} year 获取指定年份的收支明细数据
     * @apiVersion 0.1.0
     * @apiDescription 个人中心-代理用户-收支明细-获取收支明细数据
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/financeDetail")
    public BaseResult financeDetail(@LoginUser Integer userId, @RequestParam Integer year) {
        return userManager.financeDetail(userId, year);
    }

    /**
     * @api {post} /user/deductDetailList 抵扣金获取当前用户抵扣金明细列表
     * @apiGroup 个人中心
     * @apiParam {Integer} page 当前页
     * @apiParam {Integer} pageSize 页大小
     * @apiVersion 0.1.0
     * @apiDescription 抵扣金获取当前用户抵扣金明细列表
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/deductDetailList")
    public BaseResult deductDetailList(@LoginUser Integer userId, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {
        return userManager.deductDetailList(userId, page, pageSize);
    }

    /**
     * @api {post} /user/deductGoodsList 抵扣金获取当前用户抵扣金信息和可使用抵扣金的商品列表
     * @apiGroup 个人中心
     * @apiParam {Integer} page 当前页
     * @apiParam {Integer} pageSize 页大小
     * @apiVersion 0.1.0
     * @apiDescription 抵扣金获取当前用户抵扣金信息和可使用抵扣金的商品列表
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/deductGoodsList")
    public BaseResult deductGoodsList(@LoginUser Integer userId, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {
        return userManager.deductGoodsList(userId, page, pageSize);
    }

    /**
     * @api {post} /user/preCashout 获取当前代理用户提现页面数据
     * @apiGroup 个人中心
     * @apiVersion 0.1.0
     * @apiDescription 获取当前代理用户提现页面数据
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/preCashout")
    public BaseResult preCashout(@LoginUser Integer userId) {
        return userManager.preCashout(userId);
    }

    /**
     * @api {post} /user/cashoutSubmit 个人中心当前代理用户申请提现
     * @apiGroup 个人中心
     * @apiParam {BigDecimal} money 申请提现的金额
     * @apiParam {String} channel 申请提现的方式
     * @apiParam {Long} bankCardId 银行卡ID
     * @apiVersion 0.1.0
     * @apiDescription 个人中心当前代理用户申请提现
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/cashoutSubmit")
    public BaseResult cashoutSubmit(@LoginUser Integer userId,
                                    @RequestParam BigDecimal money,
                                    @RequestParam String channel,
                                    @RequestParam(required = false) Long bankCardId) {
        return userManager.cashoutSubmit(userId, money, channel, bankCardId);
    }

    /**
     * @api {post} /user/cashoutDetail 个人中心当前代理用户提现记录列表
     * @apiGroup 个人中心
     * @apiParam {Integer} page 当前页
     * @apiParam {Integer} pageSize 页大小
     * @apiVersion 0.1.0
     * @apiDescription 个人中心当前代理用户提现记录列表
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/cashoutDetail")
    public BaseResult cashoutDetail(@LoginUser Integer userId, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {
        return userManager.cashoutDetail(userId, page, pageSize);
    }

    /**
     * @api {post} /user/settleOrderList 个人中心-代理用户-分成订单-获取分成订单列表数据
     * @apiGroup 个人中心
     * @apiParam {String} keyword 搜索关键字
     * @apiParam {Integer} proxyStatus 筛选子订单代理分成状态
     * @apiParam {Integer} subOrderType 筛选指定商品类型的子订单
     * @apiParam {Integer} page 当前页
     * @apiParam {Integer} pageSize 页大小
     * @apiVersion 0.1.0
     * @apiDescription 个人中心-代理用户-分成订单-获取分成订单列表数据
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/settleOrderList")
    public BaseResult settleOrderList(@LoginUser Integer userId,
                                      @RequestParam(required = false) String keyword,
                                      @RequestParam(required = false) Integer proxyStatus,
                                      @RequestParam(required = false) String subOrderType,
                                      @RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pageSize,
                                      @RequestParam String year,
                                      @RequestParam String month) {
        return userManager.settleOrderList(userId, keyword ,proxyStatus ,subOrderType, year, month ,page ,pageSize);
    }


    /**
     * 提现记录查询
     * @param page
     * @param pageSize
     * @return
     */
    @RequestMapping("/userWithdrawalAudit")
    public BaseResult userWithdrawalAudit( @RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "10") Integer pageSize){
        return userManager.getWithdrawalRecodrInfo(page,pageSize);
    }

    /**
     * @api {post} /user/settleStatistics 个人中心-代理用户-分成统计-获取分成统计数据
     * @apiGroup 个人中心
     * @apiParam {Integer} year 年份
     * @apiVersion 0.1.0
     * @apiDescription 个人中心-代理用户-分成统计-获取分成统计数据
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/settleStatistics")
    public BaseResult settleStatistics(@LoginUser Integer userId, @RequestParam Integer year) {
        return userManager.settleStatistics(userId, year);
    }

    /**
     * @api {post} /user/settleDetail 个人中心-代理用户-分成统计-获取指定年月的结算详情
     * @apiGroup 个人中心
     * @apiParam {Integer} year 年份
     * @apiParam {Integer} month 月份
     * @apiVersion 0.1.0
     * @apiDescription 个人中心-代理用户-分成统计-获取指定年月的结算详情
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/settleDetail")
    public BaseResult settleDetail(@LoginUser Integer userId, @RequestParam Integer year, @RequestParam Integer month) {
        return userManager.settleDetail(userId, year, month);
    }




}
